<template>
  <div style="position: relative">
    <!-- 卡片视图区域 -->
    <el-card>
      <div style="margin-bottom: 5px">
        <!-- 面包屑导航区域 -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item to="/home">首页</el-breadcrumb-item>
          <el-breadcrumb-item>订单管理</el-breadcrumb-item>
          <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <div style="margin-top: 15px; width: 30%; margin-bottom: 5px">
        <!-- 搜索 -->
        <!-- clearable 清除小x号  -->
        <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable>
          <el-button
            slot="append"
            icon="el-icon-search"
            @click="newrender()"
          ></el-button>
        </el-input>
      </div>
      <el-table
        :data="tableData"
        border
        style="width: 100%; text-align: center"
      >
        <!-- <el-table-column prop="name" label="请选择" style="width: 2%">
          <input type="checkbox" />
        </el-table-column> -->
        <el-table-column type="index" label="序号" width="50">
        </el-table-column>
        <el-table-column
          prop="order_number"
          label="订单标号"
          style="width: 19%"
        >
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格" style="width: 19%">
        </el-table-column>
        <el-table-column prop="pay_status" label="是否付款" style="width: 19%">
          <div class="status">未付款</div>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" style="width: 19%">
        </el-table-column>
        <el-table-column prop="update_time" label="下单时间" style="width: 19%">
          <template slot-scope="scope">
            <p>{{ scope.row.update_time | changetime }}</p>
          </template>
        </el-table-column>
      </el-table>

      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[10, 20, 30]"
          :page-size="queryInfo.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import { orderAPI } from "@/api/index";
export default {
  data() {
    return {
      input: "",
      tableData: [],
      // 当前页
      input5: "",
      total: null,
      queryInfo: {
        query: "",
        // 当前页数
        pagenum: 1,
        // 显示一页多少条数据
        pagesize: 10,
      },
    };
  },
  // 页面刷新调用渲染
  async created() {
    this.render();
  },
  methods: {
    // 更新每页条数
    handleSizeChange(newsize) {
      // 更新页数据跳转
      this.queryInfo.pagesize = newsize;
      // 更新请求 最新条数
      this.render();
    },
    //  更新每页页数
    handleCurrentChange(newPage) {
      // 更新页数
      this.queryInfo.pagenum = newPage;
      this.render();
    },
    // 请求渲染
    async render() {
      const res = await orderAPI({
        // 默认第一页
        pagenum: this.queryInfo.pagenum,
        // 每页显示10个
        pagesize: this.queryInfo.pagesize,
        query: this.queryInfo.query,
      });
      if (res.status !== 200) {
        alert("获取订单列表失败");
        return;
      }
      this.tableData = res.data.data.goods;
      this.total = res.data.data.total;
      console.log(res);
    },
    // 数据筛选
    async newrender() {
      const res = await orderAPI({
        // 默认第一页
        pagenum: this.queryInfo.pagenum,
        // 每页显示10个
        pagesize: this.queryInfo.pagesize,
        query: this.queryInfo.query,
      });
      this.tableData = res.data.data.goods.filter((obj) => {
        console.log(obj.order_price);
        return Number(this.queryInfo.query) === obj.order_price;
      });
    },
  },

  // 过滤器
  filters: {
    changetime(val) {
      function getTimeStr(nS) {
        return new Date(parseInt(nS) * 1000)
          .toLocaleString()
          .replace(/:\d{1,2}$/, " ");
      }
      return getTimeStr(val);
    },
  },
};
</script>

<style scoped>
.input-with-select {
  background-color: #fff;
}
.status {
  width: 50px;
  border-radius: 5px;
  height: 20px;
  background: skyblue;
  font-size: 10px;
  text-align: center;
  line-height: 20px;
}
</style>